package com.ctgu.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.entity.Student;
import com.ctgu.springboot.mapper.ScInfoMapper;
import com.ctgu.springboot.entity.ScInfo;
import com.ctgu.springboot.service.ScInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cs
 * @since 2023-07-07
 */
@Service
public class ScInfoServiceImpl extends ServiceImpl<ScInfoMapper, ScInfo> implements ScInfoService {

    @Resource ScInfoMapper scInfoMapper;

    @Override
    public IPage<ScInfo> schoolPage(QueryPageParam query){
        Integer id = (Integer) query.getParam().get("sc_id");
        String name = (String) query.getParam().get("sc_name");
        String phone = (String) query.getParam().get("sc_phone");

        Page<ScInfo> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<ScInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id!=null) {
            lambdaQueryWrapper.like(ScInfo::getScId, id);
        }
        if (StringUtils.isNotBlank(name) && !"null".equals(name)) {
            lambdaQueryWrapper.like(ScInfo::getScName, name);
        }
        if (StringUtils.isNotBlank(phone) && !"null".equals(phone)) {
            lambdaQueryWrapper.eq(ScInfo::getScPhone, phone);
        }
        return scInfoMapper.schoolPage(page, lambdaQueryWrapper);
    }


    @Override
    public List<ScInfo> getList(){
        return scInfoMapper.getList();
    }
}
